package com.maila.xiaoaoschool.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.cjj.MaterialRefreshLayout;
import com.google.gson.Gson;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.adapter.NoticeAdapter;
import com.maila.xiaoaoschool.api.FindApi;
import com.maila.xiaoaoschool.entity.XiaoArt;
import com.maila.xiaoaoschool.net.VolleyInterface;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 活动通知
 * Created by mark on 2017/9/29.
 */

public class NoticeActivity extends AppCompatActivity {

    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.tv_shop_namee)
    TextView tvShopNamee;
    @BindView(R.id.ll_title)
    AutoLinearLayout llTitle;
    @BindView(R.id.lv_fujin)
    ListView lvFujin;
//    @BindView(R.id.hot_refresh)
//    MaterialRefreshLayout hotRefresh;
    NoticeAdapter noticeAdapter;
    Gson gson=new Gson();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice);
        ButterKnife.bind(this);
        noticeAdapter=new NoticeAdapter(this);
        lvFujin.setAdapter(noticeAdapter);
        initdata();
    }

    private void initdata() {
        new FindApi(this, new VolleyInterface() {
            @Override
            public void onSuccess(String result) {
                XiaoArt xiaoArt=gson.fromJson(result,XiaoArt.class);
                if(xiaoArt.getResult()==1){
                    noticeAdapter.setMdata(xiaoArt.getData());
                }else {
                    Toast.makeText(NoticeActivity.this, "暂无新的活动通知", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(VolleyError error) {

            }
        }).get_action_list(1,20);
    }

    private void requestViewFoucus(View view) {
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.requestFocus();
    }

    @Override
    protected void onResume() {
        super.onResume();
        requestViewFoucus(tvShopNamee);
    }

    @OnClick(R.id.white_return_iv)
    public void onViewClicked() {
        finish();
    }
}
